<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    var goodDaysToRobBank = function (security, time) {
      const n = security.length, ans = new Array()
      const left = new Array(n).fill(0), right = new Array(n).fill(0)
      for (let i = 1; i < n; i++) {
        if (security[i - 1] >= security[i])
          left[i] = left[i - 1] + 1
        if (security[n - i] >= security[n - 1 - i])
          right[n - 1 - i] = right[n - i] + 1
      }
      for (let i = 0; i < n; i++)
        if (left[i] >= time && right[i] >= time)
          ans.push(i)
      return ans
    };
//var goodDaysToRobBank = function(s, time) {
//     let n = s.length;
//     let up = new Array(n).fill(0);
//     let down = new Array(n).fill(0);
//     for(let i = 1 ;i < n ;i ++){ // 更新down
//         if(s[i] <= s[i-1]){
//             down[i] = down[i-1]+1;
//         }
//     }
//     for(let i =n-2 ;i >=0;i--){
//         if(s[i] <= s[i+1]){
//             up[i]=up[i+1] + 1;
//         }
//     }
//     let res=[];
//     for(let i = time ; i < n-time; i++ ){
//         if(up[i] >= time && down[i]>= time) res.push(i);
//     }
//     return res;
// };

  </script>
</body>

</html>